package com.springboot.mybatis.service.collectiondemo;

import java.util.Comparator;
import java.util.TreeSet;

public class TreeSetComparator {
    public static void main(String[] args) {
        //自定义一个比较器，并在初始化的时候用自己定义的比较器规则进行自定义排序
        Mycomparator mycomparator = new Mycomparator();
        TreeSet treeSet = new TreeSet(mycomparator);
        treeSet.add("11");
        treeSet.add("22");
        treeSet.add("33");
        treeSet.add("44");
        System.out.println(treeSet);
    }
}

class Mycomparator implements Comparator<String> {
    @Override
    public int compare(String o1, String o2) {
        return o2.compareTo(o1);
    }
}
